package com.bdzl.admin.controller.sys;

import java.util.List;
import java.util.Map;

import com.bdzl.pub.controller.BaseController;
import org.springframework.stereotype.Controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bdzl.pub.entity.sys.OrgCategoryDO;
import com.bdzl.admin.service.sys.OrgCategoryService;
import com.bdzl.pub.util.param.PageUtils;
import com.bdzl.pub.util.param.Query;
import com.bdzl.pub.util.param.R;

/**
 * 组织机构类别表
 * 
 * @author yangyicai
 * @email yangyicai@foxmail.com
 * @date 2021-03-23 13:59:22
 */
 
@Controller
@RequestMapping("/bdzl/orgCategory")
public class OrgCategoryController extends BaseController {
	@Autowired
	private OrgCategoryService orgCategoryService;
	
	@GetMapping()
	String OrgCategory(){
	    return "bdzl/orgCategory/orgCategory";
	}
	
	@ResponseBody
	@GetMapping("/list")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<OrgCategoryDO> orgCategoryList = orgCategoryService.list(query);
		int total = orgCategoryService.count(query);
		PageUtils pageUtils = new PageUtils(orgCategoryList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	String add(){
	    return "bdzl/orgCategory/add";
	}

	@GetMapping("/edit/{catId}")
	String edit(@PathVariable("catId") Integer catId,Model model){
		OrgCategoryDO orgCategory = orgCategoryService.get(catId);
		model.addAttribute("orgCategory", orgCategory);
	    return "bdzl/orgCategory/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	public R save( OrgCategoryDO orgCategory){
		if(orgCategoryService.save(orgCategory)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	public R update( OrgCategoryDO orgCategory){
		orgCategoryService.update(orgCategory);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	public R remove( Integer catId){
		if(orgCategoryService.remove(catId)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	public R remove(@RequestParam("ids[]") Integer[] catIds){
		orgCategoryService.batchRemove(catIds);
		return R.ok();
	}
	
}
